package gspushmq.v1.subscribe.handler.core;

import gspushmq.model.ApiDataMessage;
import gspushmq.model.ApiMessage;
import gspushmq.v1.produce.GGDataStorage;
import gspushmq.v1.save.SaveMassRecord;
import gspushmq.v1.thread.GGThreadPool;

public class GGApiHandler extends GGHandler {

	@Override
	public void handler() {}

	
	/**
	 * 封装生产好的数据并写入日志
	 * @param apiMess
	 * @param pushList
	 * @author yutao
	 * @date 2018年11月16日下午3:53:04
	 */
	public void handlerData(ApiMessage apiMess, Object pushList, String title) {
		ApiDataMessage apiDataMessage = GGDataStorage.ApiMessageMap.get(apiMess);
		if(apiDataMessage == null) {
			apiDataMessage = new ApiDataMessage();
			GGDataStorage.ApiMessageMap.put(apiMess, apiDataMessage);
		}
		
		apiDataMessage.setUserType(apiMess.getUser_type());
		apiDataMessage.setApiUrl(apiMess.getApi_url());
		apiDataMessage.setParams(apiMess.getParams());
		apiDataMessage.setMqType(apiMess.getMq_type());
		apiDataMessage.setMqSubType(apiMess.getMq_sub_type());
		apiDataMessage.setTitle(title);
		apiDataMessage.setContent(pushList);
		
		writeLog(apiDataMessage);
	}


	/**
	 * 写日志
	 * @param apiDataMessage
	 * @author yutao
	 * @date 2018年11月16日下午4:16:26
	 */
	private void writeLog(ApiDataMessage apiDataMessage) {
		SaveMassRecord.save(apiDataMessage);
	}
}
